package com.hd.trans.db.bean;

import android.net.Uri;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import java.util.Objects;

/**
 * @author qianjujun
 * @email qianjujun@163.com
 * @createTime 2020/9/24 14:56
 * @describe
 */
public class MediaItem implements Parcelable {

    private  long id;
    private  String mimeType;
    private  Uri uri;
    private  long size;
    private  long duration; // only for video, in ms

    private int width;
    private int height;

    private String path;

    private int orientation;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getMimeType() {
        return mimeType;
    }

    public void setMimeType(String mimeType) {
        this.mimeType = mimeType;
    }

    public Uri getUri() {
        return uri;
    }

    public void setUri(Uri uri) {
        this.uri = uri;
    }

    public long getSize() {
        return size;
    }

    public void setSize(long size) {
        this.size = size;
    }

    public long getDuration() {
        return duration;
    }

    public void setDuration(long duration) {
        this.duration = duration;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public int getOrientation() {
        return orientation;
    }

    public void setOrientation(int orientation) {
        this.orientation = orientation;
    }

    public boolean isMp4(){
        return "video/mp4".equals(mimeType);
    }

    public MediaItem() {
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof MediaItem)) return false;
        MediaItem mediaItem = (MediaItem) o;
        return (Objects.equals(getUri(), mediaItem.getUri())||(!TextUtils.isEmpty(getPath())&&Objects.equals(getPath(),mediaItem.getPath())));
    }

    @Override
    public int hashCode() {
        return Objects.hash(getMimeType(), getUri());
    }



    @Override
    public String toString() {
        return "MediaItem{" +
                "id=" + id +
                ", mimeType='" + mimeType + '\'' +
                ", uri=" + uri +
                ", size=" + size +
                ", duration=" + duration +
                ", width=" + width +
                ", height=" + height +
                ", path='" + path + '\'' +
                '}';
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(this.id);
        dest.writeString(this.mimeType);
        dest.writeParcelable(this.uri, flags);
        dest.writeLong(this.size);
        dest.writeLong(this.duration);
        dest.writeInt(this.width);
        dest.writeInt(this.height);
        dest.writeString(this.path);
        dest.writeInt(this.orientation);
    }

    public void readFromParcel(Parcel source) {
        this.id = source.readLong();
        this.mimeType = source.readString();
        this.uri = source.readParcelable(Uri.class.getClassLoader());
        this.size = source.readLong();
        this.duration = source.readLong();
        this.width = source.readInt();
        this.height = source.readInt();
        this.path = source.readString();
        this.orientation = source.readInt();
    }

    protected MediaItem(Parcel in) {
        this.id = in.readLong();
        this.mimeType = in.readString();
        this.uri = in.readParcelable(Uri.class.getClassLoader());
        this.size = in.readLong();
        this.duration = in.readLong();
        this.width = in.readInt();
        this.height = in.readInt();
        this.path = in.readString();
        this.orientation = in.readInt();
    }

    public static final Creator<MediaItem> CREATOR = new Creator<MediaItem>() {
        @Override
        public MediaItem createFromParcel(Parcel source) {
            return new MediaItem(source);
        }

        @Override
        public MediaItem[] newArray(int size) {
            return new MediaItem[size];
        }
    };
}
